#!/bin/bash
# Author：afei
# Simple install tomcat 9.0.30

# Judeg install openjdk and install jdk-1.8
if rpm -qa |grep java; then
	rm -rf $(which java)
else
    # 现在需要登录oracle官网才能下载
	wget -P /opt https://www.oracle.com/webapps/redirect/signon?nexturl=https://download.oracle.com/otn/java/jdk/8u241-b08/3d5a2bb8f8d4428bbe94aed7ec7ae784/jdk-8u241-linux-x64.tar.gz
	tar -xzf /opt/jdk-8u241-linux-x64.tar.gz -C /usr/local/
	# Set java env profile
	cat >> /etc/profile << "EOF"
export JAVA_HOME=/usr/local/jdk1.8.0_241
export JRE_HOME=${JAVA_HOME}/jre
export PATH=${JAVA_HOME}/bin:$PATH
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
EOF
source /etc/profile && sleep 2
	if rpm -qa |grep glibc.i686; then
		java -version
	else
		yum -y install glibc.i686
		java -version
	fi
fi

wget -P /opt http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.30/bin/apache-tomcat-9.0.30.tar.gz
tar -xzf /opt/apache-tomcat-9.0.30.tar.gz -C /usr/local/
#start tomcat
/usr/local/apache-tomcat-9.0.30/bin/startup.sh &